package com.cloud.netty.ProtocolTcp;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ReplayingDecoder;
import java.util.List;

/**
 * @program: netty
 * @description:
 * @author: Cloud
 * @create: 2022/4/14 16:21:30
 */
public class ProMessageDecode extends ReplayingDecoder<Void> {


    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
        System.out.println();
        System.out.println("解码器被调用");
        // 需要将得到的二进制字节码转成MessageProtocol(数据包对象)
        int length = in.readInt();
        byte[] content = new byte[length];
        in.readBytes(content);

        // 添加该数据到列表中
        out.add(new MessageProtocol(length,content));
    }
}
